package com.llt.order.service.impl;

import com.llt.order.model.OrderDetail;
import com.llt.order.mapper.OrderDetailMapper;
import com.llt.order.model.ProductDetail;
import com.llt.order.service.IOrderDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author llt
 * @since 2024-05-10
 */
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements IOrderDetailService {

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public OrderDetail getOrderById(Integer orderId) {

        OrderDetail orderDetail = getById(orderId);

        String url = "http://product-service/product/" + orderDetail.getProductId();

        ProductDetail productDetail = restTemplate.getForObject(url, ProductDetail.class);

        orderDetail.setProductDetail(productDetail);

        return orderDetail;
    }
}
